var app = getApp(), api = getApp().api;

Page({
    data: {
        selected: 0,
        list: [],
        help: ''
    },

    onLoad: function (e) {
        getApp().page.onLoad(this, e);
        var n = this;
        getApp().core.showLoading({
            title: "加载中"
        }), getApp().request({
            url: getApp().api.user.level_list,
            success: function(e) {
                n.setData({
                    list: e.data
                })
            },
            complete: function(e) {
                getApp().core.hideLoading();
            }
        });
    },
    click: function(e) {
        this.setData({
            selected: e.currentTarget.dataset.index
        });
    },

    pay: function(e) {
        var t = this, n = {}, a = t.data.selected, p = t.data.list, u = wx.getStorageSync('USER_INFO');
        console.log(Number(p[a].price));
        if(p[a].level == u.level) return void getApp().core.showModal({
            title: "提示",
            content: "您已经是此等级，无需重复购买。",
            showCancel: !1
        });

        if(Number(u.money) < Number(p[a].price)) return void getApp().core.showModal({
            title: '提示',
            content: '账户余额不足，请先充值。',
            showCancel: !1,
            success: function(e) {
                e.confirm && getApp().core.navigateTo({
                    url: '/pages/recharge/recharge'
                })
            }
        })

        n.pay_price = p[a].price, n.level = p[a].level, n.service_price = p[a].cash_service;

        n.pay_price ? (getApp().core.showLoading({
            title: "提交中"
        }),  getApp().request({
            url: getApp().api.user.level_buy,
            data: n,
            method: "POST",
            success: function(e) {
                0 == e.code ? (getApp().core.showModal({
                    title: "提示",
                    content: "会员升级成功",
                    showCancel: !1,
                    confirmText: "确认",
                    success: function(e) {
                        e.confirm && getApp().core.navigateTo({
                            url: '/pages/user/user'
                        });
                    }
                })) : getApp().core.showModal({
                    title: "提示",
                    content: e.msg,
                    showCancel: !1,
                    confirmText: "确认"
                });
            },
            complete: function() {
                getApp().core.hideLoading();
            }
        })) : getApp().core.showModal({
            title: "提示",
            content: "请选择充值金额",
            showCancel: !1
        });

    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})